import threading
from main import cycle_process
from paras import get_all_files,get_random_item_url,SLEEP


class myThread (threading.Thread):
    def __init__(self, threadID, name, all_files):
        SLEEP()
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.all_files = all_files


    def run(self):

        print ("开始线程：" + self.name)
        urls_pool = [get_random_item_url() for i in range(20)]
        cycle_process(urls_pool,self.all_files)
        print ("退出线程：" + self.name)

if __name__ == '__main__':

    # 创建新线程
    all_files = get_all_files()

    thread0 = myThread(0, "Thread-0",all_files)
    thread1 = myThread(1, "Thread-1",all_files)
    thread2 = myThread(2, "Thread-2",all_files)
    thread3 = myThread(3, "Thread-3",all_files)
    thread4 = myThread(4, "Thread-4",all_files)
    thread5 = myThread(5, "Thread-5",all_files)
    thread6 = myThread(6, "Thread-6",all_files)
    thread7 = myThread(7, "Thread-7",all_files)
    thread8 = myThread(8, "Thread-8",all_files)
    thread7 = myThread(7, "Thread-7",all_files)
    thread8 = myThread(8, "Thread-8",all_files)
    thread9 = myThread(9, "Thread-9",all_files)

    # 开启新线程
    thread0.start()
    thread1.start()
    thread2.start()
    thread3.start()
    thread4.start()
    thread5.start()
    #thread6.start()
    # thread7.start()
    # thread8.start()
    # thread9.start()


    thread0.join()
    thread1.join()
    thread2.join()
    thread3.join()
    thread4.join()
    thread5.join()
    #thread6.join()
    # thread7.join()
    # thread8.join()
    # thread9.join()

    print ("退出主线程")